<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <script src="https://cdn.staticfile.org/FileSaver.js/2014-11-29/FileSaver.min.js"></script>
  <script src="https://avuejs.com/cdn/xlsx.full.min.js"></script>
  <title>example</title>
  <style>
    .text {
      width: 100%;
      height: 300px;
    }
  </style>
</head>

<body>
  <button id="button1">导出excel</button>
  <input type="file" onchange="change(this)" />
  </br></br>
  <textarea id="text" class="text">
    [{
      "name": "张三",
      "sex": "男"
    }]
  </textarea>
</body>
<script src=" ../dist/index.js"></script>
<script>
  var text = document.getElementById('text');
  var button1 = document.getElementById('button1')
  button1.onclick = () => {
    let opt = {
      title: '文档标题',
      column: [{
        label: '复杂表头',
        prop: 'header',
        children: [
          {
            label: '姓名',
            prop: 'name'
          }, {
            label: '年龄',
            prop: 'sex'
          }
        ]
      }],
      data: JSON.parse(text.value, null, 4)
    }
    this.$Excel.excel({
      title: opt.title,
      columns: opt.column,
      data: opt.data
    });
  }
  function change(obj) {
    var files = obj.files[0];
    this.$Excel.xlsx(files)
      .then(data => {
        text.value = JSON.stringify(data.results, null, 4)
      })
  }
</script>

</html>